package com.ktg.mes.atuoVue;


import lombok.Data;
import lombok.experimental.Accessors;

import java.util.HashMap;
import java.util.Map;

@Data
@Accessors(chain = true)
public class VueButtom {

    /**
     * 权限
     */
    private String hasPermi;

    /**
     * 按钮名称
     */
    private String title;

    /**
     * logo
     */
    private String img;

    /**
     * 按钮类型
     */
    private String type;

    /**
     * API接口
     */
    private String apiPath;

    /**
     * 结合 rowFromKeyToKey,实现页面跳转，rowFromKeyToKey
     * /mes/qc/qcItemTestingResult
     */
    private String pagePath;

    /**
     * 配置跳转的查询条件
     * 逻辑：结合 pagePath,实现页面跳转， 把当前界面的某个值，转 名称传递给另外一个界面
     * key 当前界面的值的名称
     * value 跳转界面的查询条件的名称
     * 1 如：rowFromKeyToKey.put(".name","userName") 就是获取当前数据行的 name 属性值，赋值给查询条件 userName的值，
     * 2 如：rowFromKeyToKey.put("queryParams.name","userName") 就是获取当前界面，this 中的 queryParams 属性的 name 属性值，赋值给查询条件 userName的值，
     *
     * 规则：获取属性通过 . 分割。
     * 如果以 . 开头，代表获取的是 每一行中的数据的属性，否则代码的是 vue 整个界面的 this 的属性
     *
     */
    private Map<String,String> rowFromKeyToKey;


    public VueButtom(String hasPermi,String title, VueButtomType type){
        this.hasPermi = hasPermi;
        this.title = title;
        this.type = type.value;
        this.img = type.img;
    }



    /*---------------------------- set ---------------------------*/
    public VueButtom setType(VueButtomType type) {
        this.type = type.value;
        this.img = type.img;
        return this;
    }

    public VueButtom setApiPath(String apiPath) {
        this.apiPath = apiPath;
        return this;
    }

    public VueButtom setPagePath(String pagePath){
        this.pagePath = pagePath;
        return this;
    }

    public VueButtom setFromKeyToKey(String fromKey,String toKey){
        if (rowFromKeyToKey == null){
            rowFromKeyToKey = new HashMap<>();
        }
        rowFromKeyToKey.put(fromKey,toKey);
        return this;
    }

    /*------------------------------- enum ----------------------------*/

    public enum VueButtomType
    {
        add("add","el-icon-plus"),
        edit("edit","el-icon-edit"),
        delete("delete","el-icon-delete"),
        excelExport("excelExport","el-icon-download"),

        page("page","el-icon-edit");
        private final String value;
        private final String img;

        VueButtomType(String value,String img)
        {
            this.value = value;
            this.img = img;
        }

        public String value()
        {
            return this.value;
        }
        public String img(){
            return this.img;
        }
    }

}
